package com.yxch.admin.controller.comment;

import com.yxch.admin.model.commen.AuditLog;
import com.yxch.admin.model.comment.BanWord;
import com.yxch.admin.model.comment.PostAdd;
import com.yxch.admin.model.comment.PostDTO;
import com.yxch.admin.model.comment.PostTop;
import com.yxch.admin.service.comment.CommentService;
import com.yxch.admin.utils.ResultAPI;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/yxch/admin/post")
public class PostController {
    @Autowired
    private CommentService commentService;


    /**
     * 获取对应页码以及数量的发帖列表
     *
     * @param postDTO
     * @return
     */
    @GetMapping
    ResultAPI getPosts(PostDTO postDTO) {
        return commentService.getPosts(postDTO);
    }

    /**
     * 根据id获取发帖详情
     *
     * @param post_id
     * @return
     */
    @GetMapping("/{post_id}")
    ResultAPI getPostById(@PathVariable Integer post_id) {
        return commentService.getPostById(post_id);
    }

    /**
     * 审核发帖
     *
     * @param auditLog
     * @return
     */
    @PostMapping("/audit")
    ResultAPI postAudit(@RequestBody AuditLog auditLog) {
        return commentService.postAudit(auditLog);
    }

    /**
     * 分页获取敏感词
     *
     * @return
     */
    @GetMapping("/banword")
    ResultAPI getBanword(@RequestParam(defaultValue = "10") Integer pageSize,
                         @RequestParam(defaultValue = "1") Integer pageNum) {
        return commentService.getBanword(pageSize, pageNum);
    }

    /**
     * 增加或者更新敏感词
     *
     * @param banWord
     * @return
     */
    @PostMapping("/banword")
    ResultAPI addorUpdateBanword(@RequestBody BanWord banWord) {
        return commentService.addorUpdateBanword(banWord);
    }

    /**
     * 批量删除敏感词
     *
     * @param ids
     * @return
     */
    @DeleteMapping("/banword/{ids}")
    ResultAPI deleteBanword(@PathVariable List<Integer> ids) {
        return commentService.deleteBanword(ids);
    }

    /**
     * 帖子新增置顶
     *
     * @param postTop
     * @return
     */
    @PutMapping
    ResultAPI updateTop(@RequestBody PostTop postTop) {
        log.info("updateTop postTop={}", postTop);
        return commentService.updateTop(postTop);
    }

    /**
     * 管理员发布帖子
     *
     * @param postAdd
     * @return
     */
    @PostMapping
    ResultAPI addPost(@RequestBody PostAdd postAdd) {
        commentService.addPost(postAdd);
        return ResultAPI.success();
    }

    @DeleteMapping("{ids}")
    ResultAPI deletePost(@PathVariable List<Integer> ids) {
        commentService.deletePost(ids);
        return ResultAPI.success();
    }
}
